package model;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by xueal on 2018/1/30.
 */

public abstract class BaseItem {

    private int    imageId;
    private String name;

    private List<Msg> mChatList = new ArrayList<>();           // 别人和我的聊天记录

    public BaseItem(int imageId, String name) {
        this.imageId = imageId;
        this.name = name;
    }

    public int getImageId() {
        return imageId;
    }

    public void setImageId(int imageId) {
        this.imageId = imageId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void addChat(Msg msg){
        mChatList.add(msg);
    }
    public List<Msg> getChatList(){
        return mChatList;
    }

    public long getLastChatTime(){
        if (!mChatList.isEmpty()){
            return mChatList.get(mChatList.size() - 1).getTime();
        }
        return 0;
    }

    public static void removeNotChatFriend(List<BaseItem> baseItemList){
        Iterator<BaseItem> iterator = baseItemList.iterator();
        while(iterator.hasNext()) {
            BaseItem friend = iterator.next();
            if(friend.getLastChatTime() <= 0) {
                iterator.remove();
            }
        }
    }
}
